package library.and.xps.com.step.util;

import com.jude.utils.JUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import library.and.xps.com.step.App;
import library.and.xps.com.step.m.model.Runlog;

public class FileManager {
    private final String TAG = getClass().getSimpleName();
    File cacheFile;
    private static final FileManager ourInstance = new FileManager();

    public static FileManager getInstance() {
        return ourInstance;
    }

    private FileManager() {
        cacheFile = App.getInstance().getCacheDir();
    }

    public Runlog getRunlog() {
        try {
            ObjectInputStream obis = new ObjectInputStream(new FileInputStream(
                    cacheFile + File.separator + Runlog.class.getSimpleName()));
            Runlog runlog = (Runlog) obis.readObject();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
            JUtils.Log(TAG, "read faild");
        } catch (IOException e) {
            JUtils.Log(TAG, "read faild");
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        return null;
    }

//    public void writeRunlog(Runlog runlog) {
//        try {
//            ObjectOutputStream objOutput = new ObjectOutputStream(new FileOutputStream(cacheFile + File.separator + runlog.getClass().getSimpleName()));
//            objOutput.writeObject(runlog);
//            JUtils.Log(TAG, "write success");
//
//        } catch (IOException e) {
//            e.printStackTrace();
//            JUtils.Log(TAG, "write faild");
//        }
//    }

}
